package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.user.UserDao;
import com.itheima.domain.User;
import com.itheima.domain.UserExample;
import com.itheima.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findById(String id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<User> findAll(UserExample userExample, int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<User> users = userDao.selectByExample(userExample);
        return new PageInfo<>(users);
    }

    @Override
    public void add(User user) {
        userDao.insert(user);
    }

    @Override
    public void update(User user) {
        userDao.updateByPrimaryKeySelective(user);
    }


}
